'''
Created on 09/07/2011

@author: Martin
'''
import unittest
from Memory.Paging.Page import Page
from Memory.Programa import Programa
from Memory.Memoria import Memoria
from Memory.Paging.MMUP import MMUP
from SistemaOperativo.PCB import PCB


class PagingTest(unittest.TestCase):
    ## PAGE  ###
    def testPageisFull(self):
        page = Page(5, 0)
        page2 = Page(3, 0)
        page.instructions.append("prueba")
        page.instructions.append("prueba1")
        page.instructions.append("prueba2")
        page.instructions.append("prueba3")
        page.instructions.append("prueba4")
        
        page2.instructions.append("prueba")
        page2.instructions.append("prueba1")        
        

        self.assertTrue(page.isFull())
        self.assertFalse(page2.isFull())
    
    ### MMUP ###
    def testDivideMemory(self):
        mmup = MMUP(Memoria(6), None, 2)
        
        mmup.divideMemory(2)
        
        print(len(mmup.frameList))
        self.assertTrue(len(mmup.frameList) == 3)
        
    def testPaging(self):
        programa = Programa(["a","b", "c", "d", "e", "f"])
        mmup = MMUP(Memoria(6), None, 2)
        
        paged = mmup.paging(2, programa)
        print(len(paged))
        self.assertTrue(len(paged) == 3)
        
    
    def testLoadProgram(self):
        programa = Programa(["a","b", "c", "d", "e", "f"])
        mmup = MMUP(Memoria(6), None, 2)
        pcb = PCB(1, 1, 10)
        mmup.loadProgram(programa, pcb)
        
        self.assertTrue(len(pcb.pageTable.pageFrame) == 3)
        self.assertFalse(mmup.memory.list[3].instruction == None)
    
        
suite = unittest.TestLoader().loadTestsFromTestCase(PagingTest)
unittest.TextTestRunner(verbosity=2).run(suite)